//
//  ExtensionFuns.swift
//  Swift_01of30
//
//  Created by licheng ke on 2017/2/27.
//  Copyright © 2017年 licheng ke. All rights reserved.
//

import Foundation
import UIKit

extension UIImage {
    class func creatWithColor(_ color:UIColor) -> UIImage {
        let rect = CGRect.init(x: 0, y: 0, width: 10.0, height: 10);
        UIGraphicsBeginImageContextWithOptions(rect.size, false, 0);
        /*
         let context = UIGraphicsGetCurrentContext();
         context?.setFillColor(color.cgColor);
         context?.fill(rect);
         */
        
        color.setFill();
        UIRectFill(rect);
        
        let image = UIGraphicsGetImageFromCurrentImageContext()!;
        UIGraphicsEndImageContext();
        return image;
    }
    
}

extension Float {
    func formatString(format:String) -> String {
        return String(format:"%\(format)f",self);
    }
}


extension Int{
    func formatString(format:String) -> String {
        return String(format:"%\(format)d",self);
    }
}

extension UIColor {
    class func randomColor() -> UIColor {
        return UIColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1);
    }
}





